import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoke.util.HttpClientUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/10.
 */
public class https {
    public static void main(String[] s) throws Exception {
        int id = getDomainId("ysfaka.com");
        recordList(id);
    }

    private static int getDomainId(String domainUrl) throws Exception {

        Map<String, String> stringMap = new HashMap<>();
        stringMap.put("format", "json");
        stringMap.put("login_token", "30576,8659221fa98286ada86336cc005a4b27");
        String html = HttpClientUtils.sendHttpPost("https://dnsapi.cn/Domain.List", stringMap);
        //System.out.println(html);
        JSONObject jsonObject = JSONObject.parseObject(html);
        JSONObject status = jsonObject.getJSONObject("status");
        int code = status.getIntValue("code");
        if (code != 1)
            return -0;
        JSONArray domains = jsonObject.getJSONArray("domains");
        if (domains != null)
            for (int i = 0; i < domains.size(); i++) {
                JSONObject domain = domains.getJSONObject(i);
                String name = domain.getString("name");
                if (domainUrl.equals(name))
                    return domain.getIntValue("id");
            }
        return -1;
    }

    private static JSONArray recordList(int id) throws Exception {
        Map<String, String> stringMap = new HashMap<>();
        //login_token=LOGIN_TOKEN&format=json
        stringMap.put("format", "json");
        stringMap.put("login_token", "30576,8659221fa98286ada86336cc005a4b27");
        //domain_id=domain_i
        stringMap.put("domain_id", id + "");
        String html = HttpClientUtils.sendHttpPost("https://dnsapi.cn/Record.List", stringMap);
        JSONObject jsonObject = JSONObject.parseObject(html);
        JSONArray records = jsonObject.getJSONArray("records");
        return records;
    }
}
